package com.zhang.cloud.controller;

import com.zhang.cloud.entities.CommonResult;
import com.zhang.cloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {
    public static final String PAYMENT_URL = "http://localhost:8801/";
    //两个服务之间的调用
    //RestTemplate，提供了便捷访问远程Http服务的方法，是一种简单编写的访问restful服务模板类

    @Resource
    private RestTemplate restTemplate;//在config中进行的bean注入

    @GetMapping("/consumer/add")
    public CommonResult<Payment> add(Payment payment)
    {
        return restTemplate.postForObject(PAYMENT_URL+"pay/add",payment,CommonResult.class);//url,参数，返回
    }

    @GetMapping("/consumer/get/{id}")
    public CommonResult<Payment> get(@PathVariable("id") long id)
    {
        return restTemplate.getForObject(PAYMENT_URL+"pay/get/"+id,CommonResult.class);//url,返回
    }


}
